home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Sequence / SequenceLoop.h < prev    next >
Text File  |  1997-06-28  |  3KB  |  99 lines

  1. // SequenceLoop.h
  2.  
  3. #ifndef SequenceLoop_h
  4. #define SequenceLoop_h
  5.  
  6. #ifndef SequenceLoop_h
  7. #include "SequenceLoop.h"
  8. #endif
  9. #ifndef Prepositions_h
  10. #include "Prepositions.h"
  11. #endif
  12. #ifndef Assert_h
  13. #include "Assert.h"
  14. #endif
  15.  
  16. /*
  17.     SequenceLoops have three states:
  18.         finished, where Null() and Finished() are both true;
  19.         pointing to an element, where Null() and Finished() are both false;
  20.         or pointing between adjacent elements, or between an element and the end,
  21.             where Null() is true, but Finished() is false.
  22.         
  23.         The last state exists so that the loop can be in a sensible state when
  24.         the element it was pointing to was removed, but a loop can also be put
  25.         directly into that state.  After ++ or -- a SequenceLoops will always be either
  26.         at an element or finished.
  27. */
  28.  
  29. template <class Head, class Node> class Sequence;
  30.  
  31. template < class Head, class Node >
  32. class SequenceLoop
  33.   {
  34.     friend class Sequence<Head,Node>;
  35.     typedef SequenceLoop<Head,Node> Loop;
  36.     
  37.     private:
  38.         const Node *position;
  39.         const Node *next;
  40.         const Node *previous;
  41.         
  42.         const Head& head;
  43.         Loop *nextLoop;
  44.         
  45.         bool finished;
  46.     
  47.     public:
  48.         SequenceLoop( const Head& );
  49.         SequenceLoop( const Head&, AtStart );
  50.         SequenceLoop( const Head&, AtEnd );
  51.         SequenceLoop( const Head&, Nowhere );
  52.         SequenceLoop( const Head&, const Node& );
  53.         SequenceLoop( const Head&, Before, const Node& );
  54.         SequenceLoop( const Head&, After, const Node& );
  55.         SequenceLoop( const Head&, BeforeStart );
  56.         SequenceLoop( const Head&, AfterEnd );
  57.         SequenceLoop( const Loop& );
  58.         
  59.         ~SequenceLoop();
  60.         
  61.         const Head& Owner() const        { return head; }
  62.         
  63.         bool Finished() const            { return finished; }
  64.         bool Unfinished() const            { return !finished; }
  65.         
  66.         void MoveToFinish();
  67.         void MoveToFirst();
  68.         void MoveToLast();
  69.         void MoveTo( const Node& );
  70.         void MoveBefore( const Node& );
  71.         void MoveAfter( const Node& );
  72.         void MoveBeforeFirst();
  73.         void MoveAfterLast();
  74.         
  75.         void operator=( const Loop& );
  76.         
  77.         bool operator==( const Loop& ) const;
  78.         bool operator!=( const Loop& r ) const        { return !operator==( r ); }
  79.  
  80.         bool operator==( const Node& r ) const;
  81.         bool operator!=( const Node& r ) const        { return !operator==( r ); }
  82.             
  83.         bool Null() const                        { return position == 0; }
  84.         const Node *Position() const        { return position; }
  85.         
  86.         const Node *Next() const;
  87.         const Node *Previous() const;
  88.         
  89.         const Node& operator*() const        { Assert( position != 0 ); return *position; }
  90.         const Node *operator->() const    { Assert( position != 0 ); return position; }
  91.         
  92.         void operator++();
  93.         void operator++(int)                    { operator++(); }
  94.         void operator--();
  95.         void operator--(int)                    { operator--(); }
  96.   };
  97.  
  98. #endif
  99.